package fairygui.editor.dialogs
{
   import fairygui.GButton;
   import fairygui.GComboBox;
   import fairygui.GList;
   import fairygui.UIPackage;
   import fairygui.editor.Consts;
   import fairygui.editor.EditorWindow;
   import fairygui.editor.WindowBase;
   import fairygui.editor.extui.ColorInput;
   import fairygui.editor.extui.NumericInput;
   import fairygui.editor.gui.EUIProject;
   import fairygui.editor.settings.AdaptationSettings;
   import fairygui.editor.settings.CommonSettings;
   import fairygui.editor.settings.CustomProps;
   import fairygui.editor.utils.UtilsStr;
   import flash.events.Event;
   
   public class ProjectSettingsDialog extends WindowBase
   {
       
      
      private var _propsList:GList;
      
      public function ProjectSettingsDialog(param1:EditorWindow)
      {
         var _loc2_:GComboBox = null;
         super();
         _editorWindow = param1;
         this.contentPane = UIPackage.createObject("Builder","ProjectSettingsDialog").asCom;
         this.centerOn(_editorWindow.groot,true);
         _loc2_ = contentPane.getChild("scrollBarDisplay").asComboBox;
         _loc2_.items = [Consts.g.text91,Consts.g.text92,Consts.g.text93];
         _loc2_.values = ["visible","auto","hidden"];
         _loc2_ = contentPane.getChild("projectType").asComboBox;
         _loc2_.items = Consts.supportedPlatforms;
         _loc2_.values = Consts.supportedPlatforms;
         this._propsList = contentPane.getChild("customProps").asList;
         var _loc3_:int = 0;
         while(_loc3_ < 20)
         {
            this._propsList.addItemFromPool();
            _loc3_++;
         }
         var _loc4_:AdaptationSettings = _editorWindow.project.settingsCenter.adaptation;
         _loc4_.fillCombo(contentPane.getChild("defaultResolution").asComboBox);
         this.contentPane.getChild("chooseFont").addClickListener(this.__clickChooseFont);
         this.contentPane.getChild("ok").addClickListener(__actionHandler);
         this.contentPane.getChild("apply").addClickListener(this.__apply);
         this.contentPane.getChild("cancel").addClickListener(closeEventHandler);
      }
      
      override protected function onShown() : void
      {
         var _loc5_:* = null;
         var _loc7_:GButton = null;
         var _loc1_:EUIProject = _editorWindow.project;
         contentPane.getChild("projectName").text = _loc1_.name;
         contentPane.getChild("projectType").asComboBox.value = _loc1_.type;
         contentPane.getChild("disableFontAdjustment").visible = _loc1_.type == EUIProject.TYPE_EGRET || _loc1_.type == EUIProject.TYPE_LAYABOX;
         var _loc2_:CommonSettings = _loc1_.settingsCenter.common;
         contentPane.getChild("fontName").text = _loc2_.font;
         NumericInput(contentPane.getChild("fontSize")).value = _loc2_.fontSize;
         ColorInput(contentPane.getChild("textColor")).colorValue = _loc2_.textColor;
         contentPane.getChild("disableFontAdjustment").asButton.selected = !_loc2_.fontAdjustment;
         contentPane.getChild("vtScrollBarRes").text = _loc2_.verticalScrollBar;
         contentPane.getChild("hzScrollBarRes").text = _loc2_.horizontalScrollBar;
         contentPane.getChild("scrollBarDisplay").asComboBox.value = _loc2_.defaultScrollBarDisplay;
         contentPane.getChild("tipsRes").text = _loc2_.tipsRes;
         contentPane.getChild("buttonClickSound").text = _loc2_.buttonClickSound;
         contentPane.getChild("colorScheme").text = _loc2_.colorScheme.join("\n");
         contentPane.getChild("fontSizeScheme").text = _loc2_.fontSizeScheme.join("\n");
         var _loc3_:CustomProps = _loc1_.settingsCenter.customProps;
         var _loc4_:int = 0;
         for(_loc5_ in _loc3_.all)
         {
            _loc7_ = this._propsList.getChildAt(_loc4_).asButton;
            _loc7_.getChild("text").text = _loc5_;
            _loc7_.getChild("value").text = _loc3_.all[_loc5_];
            _loc4_++;
         }
         while(_loc4_ < 20)
         {
            _loc7_ = this._propsList.getChildAt(_loc4_).asButton;
            _loc7_.getChild("text").text = "";
            _loc7_.getChild("value").text = "";
            _loc4_++;
         }
         var _loc6_:AdaptationSettings = _editorWindow.project.settingsCenter.adaptation;
         contentPane.getChild("scaleMode").asComboBox.value = _loc6_.scaleMode;
         contentPane.getChild("screenMatchMode").asComboBox.value = _loc6_.screenMathMode;
         contentPane.getChild("designResolutionX").text = "" + _loc6_.designResolutionX;
         contentPane.getChild("designResolutionY").text = "" + _loc6_.designResolutionY;
         contentPane.getChild("defaultResolution").asComboBox.value = _loc6_.defaultResolution;
      }
      
      override public function actionHandler() : void
      {
         this.__apply(null);
         hide();
      }
      
      public function openFontSettings() : void
      {
         show();
         contentPane.getController("c1").selectedIndex = 1;
      }
      
      public function openScrollBarSettings() : void
      {
         show();
         contentPane.getController("c1").selectedIndex = 3;
      }
      
      public function openAdaptationSettings() : void
      {
         show();
         contentPane.getController("c1").selectedIndex = 4;
      }
      
      private function __clickChooseFont(param1:Event) : void
      {
         ChooseFontDialog(_editorWindow.getDialog(ChooseFontDialog)).open(this.__selectFont);
      }
      
      private function __selectFont(param1:String) : void
      {
         contentPane.getChild("fontName").text = param1;
      }
      
      private function __apply(param1:Event) : void
      {
         var _loc4_:String = null;
         var _loc9_:* = null;
         var _loc10_:int = 0;
         var _loc13_:GButton = null;
         var _loc14_:String = null;
         var _loc2_:EUIProject = _editorWindow.project;
         var _loc3_:CommonSettings = _loc2_.settingsCenter.common;
         _loc4_ = contentPane.getChild("fontName").text;
         if(_loc4_ != _loc3_.font)
         {
            _loc2_.globalFontVersion++;
            _loc3_.font = _loc4_;
         }
         _loc3_.fontSize = NumericInput(contentPane.getChild("fontSize")).value;
         _loc3_.textColor = ColorInput(contentPane.getChild("textColor")).colorValue;
         var _loc5_:* = !contentPane.getChild("disableFontAdjustment").asButton.selected;
         if(_loc5_ != _loc3_.fontAdjustment)
         {
            _loc2_.globalFontVersion++;
            _loc3_.fontAdjustment = _loc5_;
         }
         var _loc6_:String = contentPane.getChild("projectType").asComboBox.value;
         var _loc7_:* = _loc2_.type != _loc6_;
         _loc2_.type = _loc6_;
         _loc3_.verticalScrollBar = contentPane.getChild("vtScrollBarRes").text;
         _loc3_.horizontalScrollBar = contentPane.getChild("hzScrollBarRes").text;
         _loc3_.defaultScrollBarDisplay = contentPane.getChild("scrollBarDisplay").asComboBox.value;
         _loc3_.tipsRes = contentPane.getChild("tipsRes").text;
         _loc3_.buttonClickSound = contentPane.getChild("buttonClickSound").text;
         _loc4_ = contentPane.getChild("colorScheme").text;
         _loc4_ = UtilsStr.trim(_loc4_);
         _loc4_ = _loc4_.replace(/\r\n/g,"\n");
         _loc4_ = _loc4_.replace(/\r/g,"\n");
         _loc3_.colorScheme = _loc4_.split("\n");
         _loc4_ = contentPane.getChild("fontSizeScheme").text;
         _loc4_ = UtilsStr.trim(_loc4_);
         _loc4_ = _loc4_.replace(/\r\n/g,"\n");
         _loc4_ = _loc4_.replace(/\r/g,"\n");
         _loc3_.fontSizeScheme = _loc4_.split("\n");
         var _loc8_:CustomProps = _loc2_.settingsCenter.customProps;
         for(_loc9_ in _loc8_.all)
         {
            delete _loc8_.all[_loc9_];
         }
         _loc10_ = 0;
         while(_loc10_ < 20)
         {
            _loc13_ = this._propsList.getChildAt(_loc10_).asButton;
            _loc9_ = _loc13_.getChild("text").text;
            _loc14_ = _loc13_.getChild("value").text;
            _loc9_ = UtilsStr.trim(_loc9_);
            if(_loc9_.length > 0)
            {
               _loc8_.all[_loc9_] = _loc14_;
            }
            _loc10_++;
         }
         var _loc11_:AdaptationSettings = _editorWindow.project.settingsCenter.adaptation;
         _loc11_.scaleMode = contentPane.getChild("scaleMode").asComboBox.value;
         _loc11_.screenMathMode = contentPane.getChild("screenMatchMode").asComboBox.value;
         _loc11_.designResolutionX = parseInt(contentPane.getChild("designResolutionX").text);
         _loc11_.designResolutionY = parseInt(contentPane.getChild("designResolutionY").text);
         _loc11_.defaultResolution = contentPane.getChild("defaultResolution").asComboBox.value;
         _loc3_.save();
         _loc8_.save();
         _loc11_.save();
         var _loc12_:String = UtilsStr.trim(contentPane.getChild("projectName").text);
         if(_loc12_ != _loc2_.name)
         {
            _loc2_.rename(_loc12_);
         }
         _loc2_.save();
         if(_loc7_)
         {
            _editorWindow.plugInManager.load();
            _editorWindow.project.reload();
         }
         _editorWindow.mainPanel.setWindowTitle();
         _editorWindow.mainPanel.editPanel.refreshDocument();
         if(_editorWindow.mainPanel.self.getController("test").selectedIndex == 1)
         {
            _editorWindow.mainPanel.testPanel.applyAdaptation();
         }
      }
   }
}
